<?php
###############   COPYLEFT GPLv3 LICENSE   ###############
##
## JFX Version 0.2.7
## Website Management Software
## www.jfxcms.com
##
## Copyright 2009 GPLv3 - http://www.opensource.org/licenses/gpl-3.0.html
##
## Anthony Gallon
## oi_antz@hotmail.com
##
## Permission is hereby granted to any person having a copy of this software
## to freely use and modify as required so long as the copyright notices
## and branding remain intact.
##
## Full license details available at http://www.jfxcms.com/license
##
###############   COPYLEFT GPLv3 LICENSE   #################






$previd = (int) get('prev');
$curid = (int) get('cur');

$prevData = $DB->fetchRow("SELECT * FROM {$CONFIG->dbprefix}vms_files WHERE id = '{$previd}'");
$curData = $DB->fetchRow("SELECT * FROM {$CONFIG->dbprefix}vms_files WHERE id = '{$curid}'");


if(!is_array($prevData)){
    JFX::addError('Previous file does not exist');
    JFX::redirect($this->adminUrl);
}

if(!is_array($curData)){
    JFX::addError('Current file does not exist');
    JFX::redirect($this->adminUrl);
}

if($curData['file_type']==0 || $prevData['file_type']==0){
    JFX::addError('Cannot compare files of type "folder"');
    JFX::redirect($this->adminUrl);
}

if($curData['update_action']==3){
    JFX::addError('Current file has been deleted');
    JFX::redirect($this->adminUrl);
}


$path = $this->dirname.'/files';

if(!file_exists($path.'/'.$previd.'.vmsf')){
    JFX::addError('Cannot find file contents for previous version: '.$path.'/'.$previd.'.vmsf');
    JFX::redirect($this->adminUrl);
}

if(!file_exists($path.'/'.$curid.'.vmsf')){
    JFX::addError('Cannot find file contents for current version: '.$path.'/'.$curid.'.vmsf');
    JFX::redirect($this->adminUrl);
}

$curContent = file_get_contents($path.'/'.$curid.'.vmsf');
$prevContent = file_get_contents($path.'/'.$previd.'.vmsf');


$FC = JFX::registry('VMS_FileCompare');

$leftData = array(
    'filename' => $prevData['filename'],
    'content' => $prevContent,
    'data' => $prevData,
    'update_url' => $this->adminUrl.'/compare-files'
);
$rightData = array(
    'filename' => $curData['filename'],
    'content' => $curContent,
    'data' => $curData,
    'update_url' => $this->adminUrl.'/compare-files'
);

$FC->setLeft($leftData);
$FC->setRight($rightData);
$FC->prepare();

echo (string) $FC;








